package com.han.fu.api.business.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.han.fu.api.business.entity.Partake;
import com.han.fu.api.business.mapper.PartakeMapper;
import com.han.fu.api.business.model.ao.PartakeAddAo;
import com.han.fu.api.business.model.ao.PartakeDeleteAo;
import com.han.fu.api.business.model.ao.PartakePageAo;
import com.han.fu.api.business.model.ao.PartakeUpdateAo;
import com.han.fu.api.business.model.vo.PartakeInfoVo;
import com.han.fu.api.business.model.vo.PartakeVo;
import com.han.fu.api.business.service.IPartakeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 参与接口实现类
 *
 * @author Star.zhu
 * @since 2020-03-26
 */
@Service
public class PartakeServiceImpl extends ServiceImpl<PartakeMapper, Partake> implements IPartakeService {

    /**
     * 参与分页查询
     *
     * @param ao 查询条件
     * @return Page<PartakeVo> 分页数据
     */
    @Override
    public Page<PartakeVo> queryPartakePage(PartakePageAo ao) {
        return baseMapper.queryPartakePage(ao);
    }

    /**
     * 参与明细查询
     *
     * @param id 明细ID
     * @return
     */
    @Override
    public PartakeInfoVo queryPartakeDetail(String id) {
        PartakeInfoVo partakeInfoVo = new PartakeInfoVo();
        Partake partake = super.getById(id);
        if (null != partake) {
            BeanUtils.copyProperties(partake, partakeInfoVo);
        }
        return partakeInfoVo;
    }

    /**
     * 参与新增数据
     *
     * @param ao 数据
     */
    @Override
    public void addPartake(PartakeAddAo ao) {
        Partake entity = new Partake();
        BeanUtils.copyProperties(ao, entity);
        super.save(entity);
    }

    /**
     * 参与修改数据
     *
     * @param ao 数据
     */
    @Override
    public void updatePartake(PartakeUpdateAo ao) {
        Partake entity = new Partake();
        BeanUtils.copyProperties(ao, entity);
        super.updateById(entity);
    }

    /**
     * 参与删除数据
     *
     * @param ao 数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deletePartake(PartakeDeleteAo ao) {
        for (String id : ao.getIds()) {
            super.removeById(id);
        }
    }

}